package com.yms.juc;

/**
 * @version : 1.0
 * @author: yangmingsong
 * @date: 2022/7/9-07-09-20:44
 * @description: spring5Test 原子性
 */
public class AtomicTestAndSourceCode {

    //创建共享变量，给多个线程进行操作
    private   int a = 0;


    public  int add(){
        return a++;
    }

    public static void main(String[] args) {
        AtomicTestAndSourceCode atomicTestAndSourceCode = new AtomicTestAndSourceCode();
        for (int i = 0 ;i<10;i++){
            new Thread(()->{
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+": "+atomicTestAndSourceCode.add());

            }).start();
        }
    }
}


